<template>
  <div class="w-h-100" style="display: flex">
    <img src="../assets/img/login.jpg" alt="背景图" class="back-img">
    <div class="login-div">
      <span class="span-style">智慧校园管理系统</span>
      <br>
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="150px" class="demo-ruleForm">
        <el-form-item prop="user">
          <el-input placeholder="请输入账号"
                    v-model="ruleForm.user">
            <i slot="prefix" class="el-input__icon el-icon-user-solid"></i>
          </el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input type="password"
                    placeholder="请输入密码"
                    v-model="ruleForm.password">
            <i slot="prefix" class="el-input__icon el-icon-lock"></i>
          </el-input>
        </el-form-item>
        <el-form-item prop="userType">
          <el-radio-group v-model="ruleForm.userType">
            <el-radio class="font-color" label="管理员"></el-radio>
            <el-radio class="font-color" label="学生"></el-radio>
            <el-radio class="font-color" label="教师"></el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item>
          <el-button class="login-button" type="primary" @click="login('ruleForm')">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Login',
  data() {
    return {
      ruleForm: {
        user: '',
        password: '',
        userType: '',
      },
      rules: {
        user: [
          {required: true, message: '请输入账户名！', trigger: 'blur'},
          {min: 3, max: 5, message: '长度在 3 到 6 个字符', trigger: 'blur'}
        ],
        password: [
          {required: true, message: '请选输入密码！'}
        ],
        userType: [
          {required: true, message: '请选择用户类型', trigger: 'change'}
        ],

      }

    }
  },
  methods: {

    login(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.ruleForm.user === "videoUpload" && this.ruleForm.password === "videoUpload") {
            //在浏览器的会话存储中存储登录状态（每次登录成功就会存储）
           // window.sessionStorage.setItem("loginStatus","success")
           window.localStorage.setItem("loginStatus","success")
            this.$message({
              showClose: true,
              message: '恭喜你，登录成功！',
              type: 'success'
            });
            this.$router.push({name: "home"})
          } else {
            this.$message({
              showClose: true,
              message: '登录失败，账号或者密码错误！',
              type: 'error'
            });

          }
        } else {
          return false;
        }
      });
    },

  }

}
</script>

<style scoped>
.back-img{
  display: flex;
  background-color: rgba(0, 0, 0, 1);
  width:100%;
  filter: brightness(50%);
}
.login-div {
  position: absolute;
  top: 160px;
  left: 400px;
}
.login-button{
  width: 320px;
}
.font-color{
  color: white;
}
.span-style{
  position: relative;
  display: flex;
  left: 62px;
  justify-content: center;
  align-items: center;
  color: white;
  font-weight: bold;
  font-size: 20px;
}
</style>